<?php

abstract class xpfw {

    private $user;

    public function getUser() {
        return isset($_SESSION['user']) ? $_SESSION['user'] : null;
    }

    public function setUser(user $user) {
        if(!isset($_SESSION['user']))
            $_SESSION['user'] = $user;
    }

    protected function loadFiles($dir) {
        $classes = opendir($dir);
        while ($class = readdir($classes)) {
            if ($class != '.' && $class != '..')
                include $dir . $class;
        }
    }

    protected function throwError($error) {
        header('Location: ' . link_to('home/error' . $error));
        exit;
    }

    protected function log($message, $error = null) {
        $log = fopen(xpfwPath . 'log.log', 'a+');
        fwrite($log, date('Y-m-d H:i:s ') . ($error ? '[' . $error . '] ' : '') . $message . "\n");
        fclose($log);
        if ($error)
            $this->throwError($error);
    }

}

?>
